USE ASLB 
GO
IF (OBJECTPROPERTY ( OBJECT_ID('SessionTimeout'), 'IsProcedure' ) IS NOT NULL)
BEGIN
   DROP PROC SessionTimeout
END
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO


CREATE PROC [dbo].[SessionTimeout] 
       
AS
/***********************************************************************************
** Name      : SessionTimeout
**
** File Name : SessionTimeout.sql
**
** Desc      : 
**
** Called By : 
**
** Calls     : 
**
** Returns   :
** Author    : jocaplan
**
** Date      : 03/30/2009
**
** Parameters: 
                

** Usage     :
               

************************************************************************************
** Change History
************************************************************************************
** Date        Author     Description
** ----------  ---------  ----------------------------------------------------------
**********************************************************************************/

SET NOCOUNT ON

DECLARE
   @TimeoutTime float
   
   
-- Get the timeout parameter from the parameters table
SELECT
   @TimeoutTime = ParamNumber
FROM
   Parameters
WHERE PARAMNAME = 'SessionTimeout'

-- Delete the sessions that have expired
DELETE FROM [Session]
where DATEDIFF(minute, LastRequestDate, GETDATE()) >= @TimeoutTime
